package com.self.cgqcompose.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.self.cgqcompose.BottomTabs
import com.self.cgqcompose.mock.MockJson
import com.self.cgqcompose.ui.components.BottomBar
import com.self.cgqcompose.ui.pages.AiScreen
import com.self.cgqcompose.ui.pages.DigitalScreen
import com.self.cgqcompose.ui.pages.HomeScreen
import com.self.cgqcompose.ui.pages.ProfileScreen
import com.self.cgqcompose.ui.pages.TvScreen
import com.self.cgqcompose.ui.test.RowTest
import com.self.cgqcompose.ui.ui.theme.CgqComposeTheme

class TestActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            CgqComposeTheme {
//                Scaffold(modifier = Modifier.fillMaxSize(), containerColor = Color.Red) { innerPadding ->
//                    RowTest()
//                }
                ContentUi()
            }
        }
    }
}

@Composable
fun ContentUi(){
    val navController = rememberNavController()

    Column(modifier = Modifier.fillMaxSize().background(Color.Red)) {
        RowTest()
        BottomTabs(navController)
        Box(modifier = Modifier.size(100.dp))
    }
}

@Composable
fun BottomTabs(controller: NavController) {
    val context = LocalContext.current;
    val tabs = MockJson.loadMockDataBottomTabs(context)

    var currentIndex = 0
    var selectedIndex by remember { mutableIntStateOf(0) }

    BottomBar(tabs, selectedIndex, onItemSelected = {
        selectedIndex = it
        when (it) {
            0 -> controller.navigate("home")
            1 -> controller.navigate("tv")
            2 -> controller.navigate("ai")
            3 -> controller.navigate("digital")
            4 -> controller.navigate("profile")
        }
    })

}